<?php

namespace App\Admin\Controllers;

use App;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;
use App\Models\TestingDevUrl;
use TestingDevUrlService;

class TestingDevUrlController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {
            $content->header(trans('backend.testing_developer_url.title.list'));
            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {
            $content->header(trans('backend.testing_developer_url.title.edit'));
            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {
            $content->header(trans('backend.testing_developer_url.title.add'));
            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(TestingDevUrl::class, function (Grid $grid) {
            $grid->model()->orderBy('id', 'desc');
            $grid->id('id');
            $grid->redirect_url(trans('backend.testing_developer_url.column.redirect_url'));
            $grid->union_code(trans('backend.testing_developer_url.column.union_code'));
            $grid->disableExport();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(TestingDevUrl::class, function (Form $form) {
            $form->text("id");
            $form->text("redirect_url",trans('backend.testing_developer_url.column.redirect_url'));
            $form->text("union_code",trans('backend.testing_developer_url.column.union_code'));
        });
    }

    public function options()
    {
        return TestingDevUrlService::getResultOptions();
    }
}
